package com.qf.web;



import com.qf.domain.PageBean;
import com.qf.domain.Student;
import com.qf.service.StudentService;
import com.qf.service.impl.StudentServiceImpl;
import com.qf.utils.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/listStudent")
public class PageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取前端页码数
        String currentPage = req.getParameter("currentPage");
        String pageSize = req.getParameter("pageSize");
        int page_cur = 1;
        int page_size = 4;
        try {
            if (!StringUtils.isEmpty(currentPage)) {
                page_cur = Integer.parseInt(currentPage);
            }
            if (!StringUtils.isEmpty(pageSize)) {
                page_size = Integer.parseInt(pageSize);
            }
            StudentService service = new StudentServiceImpl();
            PageBean<Student> listAll = service.findListAll(page_cur, page_size);

            req.setAttribute("listAll", listAll.getList());
            req.getRequestDispatcher("/admin/page123.jsp").forward(req, resp);
        } catch (Exception e) {
            e.printStackTrace();
            req.setAttribute("msg", "查询失败"+e.getMessage());
            req.getRequestDispatcher("/msg.jsp").forward(req, resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
